Show the URI in a tooltip. (#505480, Teppo Turtiainen)
authorMatthias Clasen <mclasen@redhat.com>
Sat, 16 Feb 2008 05:28:22 +0000 (05:28 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sat, 16 Feb 2008 05:28:22 +0000 (05:28 +0000)
2008-02-16  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtklinkbutton.c: Show the URI in a tooltip.  (#505480,
        Teppo Turtiainen)

svn path=/trunk/; revision=19596

ChangeLog
gtk/gtklinkbutton.c

index dc6b8017d2558a199a80d00770cdbbf98a4632d1..93107c5a157c794b6c148e517f9e51d58300a854 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-16  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtklinkbutton.c: Show the URI in a tooltip.  (#505480,
+       Teppo Turtiainen)
+
 2008-02-15  Matthias Clasen  <mclasen@redhat.com>
 
        * gdk/Makefile.am: Don't install private headers. (#463510)
index 927b9b6f1fc61d802b138f41c40e56358eda027d..751f915960ba24e6418e1eabddd1d956559720f4 100644 (file)
@@ -38,6 +38,7 @@
 #include "gtkmenu.h"
 #include "gtkmenuitem.h"
 #include "gtkstock.h"
+#include "gtktooltip.h"
 
 #include "gtklinkbutton.h"
 
@@ -92,6 +93,12 @@ static void gtk_link_button_drag_data_get_cb (GtkWidget        *widget,
                                              guint             _info,
                                              guint             _time,
                                              gpointer          user_data);
+static gboolean gtk_link_button_query_tooltip_cb (GtkWidget    *widget,
+                                                  gint          x,
+                                                  gint          y,
+                                                  gboolean      keyboard_tip,
+                                                  GtkTooltip   *tooltip,
+                                                  gpointer      data);
 
 
 static const GtkTargetEntry link_drop_types[] = {
@@ -159,6 +166,9 @@ gtk_link_button_init (GtkLinkButton *link_button)
                    G_CALLBACK (gtk_link_button_leave_cb), NULL);
   g_signal_connect (link_button, "drag_data_get",
                    G_CALLBACK (gtk_link_button_drag_data_get_cb), NULL);
+  g_object_set (link_button, "has-tooltip", TRUE, NULL);
+  g_signal_connect (link_button, "query-tooltip",
+                    G_CALLBACK (gtk_link_button_query_tooltip_cb), NULL);
   
   /* enable drag source */
   gtk_drag_source_set (GTK_WIDGET (link_button),
@@ -538,8 +548,8 @@ gtk_link_button_new (const gchar *uri)
     }
   
   retval = g_object_new (GTK_TYPE_LINK_BUTTON,
-                        "uri", uri,
                         "label", utf8_uri,
+                        "uri", uri,
                         NULL);
   
   g_free (utf8_uri);
@@ -577,6 +587,30 @@ gtk_link_button_new_with_label (const gchar *uri,
   return retval;
 }
 
+static gboolean 
+gtk_link_button_query_tooltip_cb (GtkWidget    *widget,
+                                  gint          x,
+                                  gint          y,
+                                  gboolean      keyboard_tip,
+                                  GtkTooltip   *tooltip,
+                                  gpointer      data)
+{
+  GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
+  const gchar *label, *uri;
+
+  label = gtk_button_get_label (GTK_BUTTON (link_button));
+  uri = link_button->priv->uri;
+
+  if (label && *label != '\0' && uri && strcmp (label, uri) != 0)
+    {
+      gtk_tooltip_set_text (tooltip, uri);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+
 /**
  * gtk_link_button_set_uri:
  * @link_button: a #GtkLinkButton
@@ -590,17 +624,18 @@ void
 gtk_link_button_set_uri (GtkLinkButton *link_button,
                         const gchar   *uri)
 {
-  gchar *tmp;
+  GtkLinkButtonPrivate *priv;
 
   g_return_if_fail (GTK_IS_LINK_BUTTON (link_button));
   g_return_if_fail (uri != NULL);
-  
-  tmp = link_button->priv->uri;
-  link_button->priv->uri = g_strdup (uri);
-  g_free (tmp);
 
-  link_button->priv->visited = FALSE;
-  
+  priv = link_button->priv;
+
+  g_free (priv->uri);
+  priv->uri = g_strdup (uri);
+
+  priv->visited = FALSE;
+
   g_object_notify (G_OBJECT (link_button), "uri");
 }